

<template>

  <div class="flex h-screen ">
  <!--        左侧部分-->
  <div class="w-28 bg-gray-100 flex flex-col border-r">
    <!-- 左侧菜单 -->
    <div class="flex select-none  border-t flex-col justify-start items-start  h-full ">

      <div class="fixed w-28 flex top-0  pb-3 left-0 border-r">
        <router-link
            v-for="(route, index) in routes"
            :key="`route-${index}`"
            :to="route.path"
            class="p-2 pl-4 mt-2 w-full text-left hover:bg-gray-400 cursor-pointer"
            :class="currIndex == index ? 'bg-gray-300' :''"

            @click="currIndex=index"
        >
          <i class="fas mr-2"  :style="'color:'+route.color" :class="route.icon"></i> {{ route.name }}
        </router-link>
      </div>




    <div class="fixed bottom-0 left-0 w-28 border-r">
      <div class=" mt-auto w-full ">
        <MiniNav class="bg-gray-200" :winType="WindowsType.Main"></MiniNav>
      </div>
      <!-- 左侧菜单-底部按钮-->
<!--      <div v-if="!storeGlobal.IsLogin" class="hover:bg-gray-400 bg-white mb-0.5  w-full text-left p-2 pl-4 cursor-pointer" @click="showPopLogin">-->
<!--        <i class="fas fa-user"></i> 登录/注册-->
<!--      </div>-->

<!--      <div v-if="storeGlobal.IsLogin" class=" bg-white mb-0.5  w-full text-left p-2 pl-4 hover:bg-gray-200 cursor-pointer"  @click="showPopLogin">-->
<!--        <i class="fas fa-user"></i> {{storeGlobal.UserInfo.username == null  ? "用户中心" :storeGlobal.UserInfo.username}}-->
<!--      </div>-->
            <div  @click="storeWin.SaveCurrWinSize(WindowsType.Main)" class=" bg-white mb-0.5  w-full text-left p-2 pl-4 hover:bg-gray-200 cursor-pointer">
              <i style="color: #1899ad" class="fas fa-desktop"></i> 记住屏幕
              <q-tooltip>记住主界面屏幕的尺寸和位置信息</q-tooltip>
            </div>

    </div>

<!--      <div class="p-2 pl-4  w-full text-left hover:bg-white cursor-pointer">-->
<!--        <i class="fas fa-sign-out-alt "></i>退出-->
<!--      </div>-->
    </div>
  </div>
  <div class="flex-1 bg-white  border-t">
    <!-- 右侧内容 -->
    <div class="">
      <router-view/>
    </div>
  </div>




  <!-- 弹窗区域-->
  <q-dialog v-model="storeWin.Main.ShowPop"  no-backdrop-dismiss style="draggable:false">
    <div :class="storeWin.Main.ShowPopWidth" class=" bg-white shadow-lg rounded-lg overflow-hidden" draggable="false">
      <!-- 标题栏 -->
      <div class="flex items-center justify-between px-3 py-2 bg-cyan-3">
        <h3 class="text-sm font-medium text-gray-800">{{storeWin.Main.ShowPopTitle}}</h3>
        <button class="text-gray-600 hover:text-gray-800 focus:outline-none" @click="storeWin.CloseMainPop()">
          <svg class="h-5 w-5 fill-current" viewBox="0 0 24 24">
            <path
                d="M18.7,6.3c-0.4-0.4-1-0.4-1.4,0L12,10.6L7.7,6.3c-0.4-0.4-1-0.4-1.4,0c-0.4,0.4-0.4,1,0,1.4l4.3,4.3l-4.3,4.3c-0.4,0.4-0.4,1,0,1.4c0.2,0.2,0.5,0.3,0.7,0.3s0.5-0.1,0.7-0.3l4.3-4.3l4.3,4.3c0.2,0.2,0.5,0.3,0.7,0.3s0.5-0.1,0.7-0.3c0.4-0.4,0.4-1,0-1.4L13.4,12l4.3-4.3C19.1,7.3,19.1,6.7,18.7,6.3z"></path>
          </svg>
        </button>
      </div>


      <!-- 主体区域 -->
      <div class="px-3 py-2"  v-if="storeWin.Main.ShowPopType == ShowPopType.Login">
        <login @close="closePopup"></login>
      </div>

<!--      用户中心-->
      <div class="px-3 py-2"  v-if="storeWin.Main.ShowPopType == ShowPopType.UserInfo">
        <UserInfo @close="closePopup"></UserInfo>
      </div>
    </div>
  </q-dialog>

</div>


</template>


<script setup lang="ts">
import {onMounted, ref} from 'vue'
import {useRouter} from 'vue-router';

import {WindowSetAlwaysOnTop, WindowSetTitle} from "../../wailsjs/runtime";
import {useIndexStore} from "../store";


import {ShowPopType, useWindowsStore, WindowsType} from "../store/windows";
import {GetBool} from "../../wailsjs/go/dbservice/DbConfigService";
import {ConfigKeySysWinTop} from "../constant/config_keys";
import {service} from "../../wailsjs/go/models";
import {MainWinTitle} from "../constant/common";
import Login from "../layout/login.vue";
import {useGlobalStore} from "../store/global";
import UserInfo from "../layout/UserInfo.vue";
import {ApiGetNotice, GetBackUrl} from "../../wailsjs/go/service/BackService";
import {RespCodeOk} from "../constant/enums/RespCode";
import MiniNav from "../components/MiniNav.vue";
import {SetPosByConfig, SetSizeByConfig} from "../utils/SetWinInfo";


let storeWin=ref(useWindowsStore())
let storeIndex = ref(useIndexStore())
let storeGlobal=ref(useGlobalStore())
let router=useRouter()
//市场
const routes = ref([
  {path: "/", name: "首页", icon: "fa-home",color:"#3F51B5"},
  {path: "/prompt_shop", name: "指令库", icon: "fa-shop",color:"#6c3fb5"},
  {path: "/setting", name: "设置", icon: "fa-cog",color:"#9C27B0"},
  {path: "/chat_dialogs", name: "对话", icon: "fa-comment",color:"#FF5722"},
  {path: "/clipboards", name: "剪贴板", icon: "fa-clipboard",color:"#2196F3"},
  {path: "/about", name: "关于", icon: "fa-info-circle",color:"#2196F3"},

])
const currIndex = ref(0)

onMounted(async () => {
  await  SetSizeByConfig(WindowsType.Main)
  await  SetPosByConfig(WindowsType.Main)
  // let CurrPos=await WindowGetPosition()
  // //保存初始坐标
  // storeWin.value.InitMainFirstPos(CurrPos.x,88)
  // //窗口置顶判断
  // let size:ScreenSize=await GetScreenSize()
  // console.log(size,"-----Screen size value")
  // let w=getPercentValue(65,size.width)
  // let h=getPercentValue(80,size.height)
  // console.log(w,h,"-----w,h, value")
  // await WindowSetSize(MainWindowWidth,MainWindowHeight)
  // //使用首次启动时的坐标
  // WindowSetPosition(
  //     storeWin.value.Main.FirstPos.x,
  //     // storeWin.value.Main.FirstPos.y,
  //     88
  // )


  //变更置顶状态
  let isTop=await GetBool(ConfigKeySysWinTop)
  WindowSetAlwaysOnTop(isTop) //窗口置顶

  await router.push("/")
  WindowSetTitle(MainWinTitle)
  //ChangeLangType(LangTypeEn)
  await storeGlobal.value.CheckLogin()

  GetBackUrl().then(url=>{
    storeGlobal.value.BackUrl=url
  })

  ApiGetNotice().then(res=>{
     console.log(res," ApiGetNotice---res")
    if(res.code == RespCodeOk){
      storeGlobal.value.Notices=res.data
    }
  })



})

function closePopup(){
  storeIndex.value.App.ShowPop=false
}

function getPercentValue(per:number, ori:number):number {
  return Math.round((per / 100) * ori);
}
function ToInt(floatNum :number){
  const num = Math.round(floatNum);
  return Number.parseInt(num.toString(), 10)
}

async function showPopLogin() {
    storeGlobal.value.CheckLogin().then(isLogin=>{
      console.log("已登录 ---",isLogin)
      if (isLogin) {

        storeWin.value.MainShowPop(ShowPopType.UserInfo, '用户中心', 'w-full')
      } else {
        storeWin.value.MainShowPop(ShowPopType.Login, '登录/注册', 'w-80')
      }
    })
}
// EventsOn("event1", function (data) {
//   GetListText().then((res: Array<string>) => {
//     console.log("list", res)
//   })
//   ToastInfo("event事件被触发:剪贴板变化--" + data)
// })


</script>


<style>
.main {
  height: 100vh;
  /* 设置最大高度为视口高度 */
  margin: 0;
  /* 取消默认边距 */
  padding: 0;
  /* 取消默认内边距 */
  overflow-y: auto;
  /* 禁止垂直滚动条 */
}

.nav-link-active {
  border-bottom-width: 2px;
  border-bottom-style: solid;
  border-bottom-color: orange;
}
</style>